if UnitLevel"player" >= MAX_PLAYER_LEVEL then return end

SlashCmdList.JERRY_XP = function (input)
	local xp, max, rest = UnitXP"player", UnitXPMax"player", GetXPExhaustion()
	local s = string.format("%.1f%% (%d restant)", xp / max * 100, max - xp)
	if rest then
		s = s .. string.format(" (+%.1f%% reposé)", rest / max * 100)
	end
	print(s)
end
SLASH_JERRY_XP1="/xp"

local f = CreateFrame"Frame"
f.dataobj = LibStub"LibDataBroker-1.1":NewDataObject("JerryXP", {
	type = "data source",
	value = "-",
	suffix = "XP",
})

f:RegisterEvent"PLAYER_XP_UPDATE"
f:RegisterEvent"PLAYER_LOGIN"
local delta
f:SetScript("OnEvent", function (self, event, ...)
	local xp = UnitXPMax"player" - UnitXP"player"
	if event == "PLAYER_XP_UPDATE" then
		delta = self.dataobj.value - xp
	end
	self.dataobj.value = xp
end)

function f.dataobj.OnTooltipShow(tooltip)
	local xp, max, rest = UnitXP"player", UnitXPMax"player", GetXPExhaustion()
	local left = max - xp
	tooltip:AddLine"Experience"
	tooltip:AddDoubleLine("Courant", string.format("%.1f%% (%d / %d)", xp / max * 100, xp, max), 1, 1, 1)
	tooltip:AddDoubleLine("Restant", string.format("%.1f%% (%d)", left / max * 100, left), 1, 1, 1)
	if rest then
		tooltip:AddDoubleLine("Réposé", string.format("%.1f%% (%d)", rest / max * 100, rest), 1, 1, 1)
	end
	if delta then
		tooltip:AddDoubleLine("TTXP", string.format("%.1f", left / delta), 1, 1, 1)
	end
	tooltip:Show()
end
